package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.UsmZlRecordPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.UsmZlRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app-api/usmzlrecord")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppUsmZlRecordController {
    private UsmZlRecordService usmZlRecordService;
    @Autowired
    public void setUsmZlRecordService(UsmZlRecordService usmZlRecordService) {
        this.usmZlRecordService = usmZlRecordService;
    }

    @PostMapping("/addUsmZlRecord")
    public SaResult addUsmZlRecord(@RequestBody UsmZlRecordPO usmZlRecordPO){
        int res= usmZlRecordService.addRecord(usmZlRecordPO);
        if(res<1) return SaResult.error("添加失败");
        return SaResult.ok();
    }

    @GetMapping("/getRecordByLotNo")
    public  SaResult getRecordByLotNo(String lotNo){
        return SaResult.data(usmZlRecordService.getRecordByLotNo(lotNo));
    }

    @GetMapping("/getRecordByFullLotNo")
    public  SaResult getRecordByFullLotNo(String fullLotNo){
        log.info("fullLotNo:{}",fullLotNo);
        return SaResult.data(usmZlRecordService.getRecordByFullLotNo(fullLotNo));
    }

    @GetMapping("/getUsmZlRecordByID")
    public SaResult getUsmZlRecordByID(Integer recordID){
        UsmZlRecordPO usmZlRecordPO = usmZlRecordService.getUsmZlRecordByID(recordID);
        if(ObjectUtil.isEmpty(usmZlRecordPO)) return SaResult.error("异常数据");
        return SaResult.data(usmZlRecordPO);
    }

    @PostMapping("/uptUsmZlRecord")
    public SaResult uptUsmZlRecord(@RequestBody UsmZlRecordPO usmZlRecordPO){
        int res= usmZlRecordService.uptRecord(usmZlRecordPO);
        if(res<1) return SaResult.error("修改失败");
        return SaResult.ok();
    }

    @PostMapping("/delUsmZlRecord")
    public SaResult delUsmZlRecord(@RequestBody UsmZlRecordPO usmZlRecordPO){
        int res= usmZlRecordService.delRecord(usmZlRecordPO.getRecordID());
        if(res<1) return SaResult.error("删除失败");
        return SaResult.ok();
    }
}
